package com.jsfcomponent.paging.managed;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.Set;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.sql.DataSource;

import com.jsfcomponent.domain.Bee;
import com.jsfcomponent.domain.Honey;


public class BeeHiveController {

	private Bee bee;
	private Honey honey;

	private HashMap<String,Integer> infomap=new HashMap<String,Integer>();
    

    public Map<String, Integer[]> getComplex() {
        return complex;
    }

    public void setComplex(Map<String, Integer[]> complex) {
        this.complex = complex;
    }

    private Map<String, Integer[]> complex=new HashMap<String, Integer[]>();



    public List<String> getItems() {
        return items;
    }

    public void setItems(List<String> items) {
        this.items = items;
    }

    private List<String> items=new ArrayList<String>();
	private Integer keyA= 10;
	private Integer keyB= 20;
	
	public HashMap<String, Integer> getInfomap() {
		return infomap;
	}

	public void setInfomap(HashMap<String, Integer> infomap) {
		this.infomap = infomap;
	}

	public Honey getHoney() {
		return honey;
	}

	public void setHoney(Honey honey) {
		this.honey = honey;
	}

	public Bee getBee() {
		return bee;
	}

	public void setBee(Bee bee) {
		this.bee = bee;
	}

	public BeeHiveController() {
		init();

	}

	private void init() {
        //Populate data	
		infomap.put("RefKeyA", keyA);
		infomap.put("RefKeyA", keyB);
        for(int i=0;i<5;i++){
            infomap.put("key"+i, i);
            items.add("Item "+i);
            Integer[]  val= new Integer[3];
            for(int j=0;j<3;j++){
                val[j]=j;
            }
            complex.put("key"+i, val);
        }


		// Create EntityManagerFactory for a persistence unit called PU_JSFDumpDemo.
       EntityManagerFactory emf = Persistence.createEntityManagerFactory("PU_JSFDumpDemo");
       // create EntityManager
       EntityManager em = emf.createEntityManager();
        // Get a transaction instance and start the transaction
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        honey=new Honey();  
        honey.setName("Country Honey");
        honey.setTaste("semi-sweet");
        
        bee = new Bee();
        bee.setName("I am one Angry Bee");  
        bee.setHoney(honey);
        
        Set<Bee> beeCollection=new HashSet<Bee>();
        beeCollection.add(bee);
		honey.setBeeCollection(beeCollection);
        
//        em.persist(bee);
//        bee=em.find(Bee.class, 1);
        System.out.println("Bee name=::"+bee);
        tx.commit();
	
	}
	
	public String actionA(){
		
		return "action";
	}
	
	public String actionB(){
		return "validate";
	}
	
	
}
